package com.itheima.manager.service.imp;

import com.itheima.manager.mapper.ContactMapper;
import com.itheima.manager.pojo.Contact;
import com.itheima.manager.service.ISelectByNameService;
import com.itheima.manager.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

public class SelectByNameServiceImp implements ISelectByNameService {
    @Override
    public Contact selectAllByName(String name) {
        SqlSession session = SqlSessionUtil.getSession();
        ContactMapper mapper = session.getMapper(ContactMapper.class);

        Contact contact = mapper.selectAllByName(name);

        session.close();

       return contact;
    }

    @Override
    public List<Contact> selectLink(Map map) {
        SqlSession session = SqlSessionUtil.getSession();
        ContactMapper mapper = session.getMapper(ContactMapper.class);

        List<Contact> contacts = mapper.selectAllByNameAndAge(map);
        return contacts;
    }


     public List<Contact> selectLimit(Map map){
         SqlSession session = SqlSessionUtil.getSession();
         ContactMapper mapper = session.getMapper(ContactMapper.class);
         List<Contact> contacts = mapper.selectLimit(map);

         return contacts;

     }

}
